from langchain.tools import BaseTool
import datetime
from pydantic import BaseModel,Field,ConfigDict
from typing import Any,Type


#定义工具类输入的参数格式
class GetTimeInput(BaseModel):
    question:str = Field(...,description="问题")

#定义工具类
class GetTimeTool(BaseTool):
    #允许模型接受非标准数据类型
    model_config = ConfigDict(arbitrary_types_allowed=True)
    def __init__(self,**kwargs:Any):
        super().__init__(
            name = "get_time_tool",
            description = "主要用于获取当前的时间，必须输入参数是问题",
            **kwargs
        )
    #指定模型的输入参数必须是GetTimeInput:
    args_schema : Type[BaseModel] = GetTimeInput

    def _run(self, question:str) :
        time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        return time
